package com.zzf.mall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;

/**
 * 订单确认页数据VO对象
 *
 * @Author 赵振飞
 * @Date 2022/10/28
 * @Version 1.0
 */
@Data
public class OrderConfirmVO {

    //收货人及收货地址
    @Getter @Setter
    List<MemberAddressVO> address;

    //购物车选中的商品信息
    @Getter @Setter
    List<OrderItemVO> items;

    @Getter @Setter
    private String orderToken;

    public Integer getCountNum(){
        int count = 0;
        if (items != null){
            for (OrderItemVO item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    //总金额
    //BigDecimal total;
    public BigDecimal getTotal(){
        BigDecimal sum = new BigDecimal(0);
        if (items != null){
            for (OrderItemVO item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    //需要支付的总金额
    //BigDecimal payTotal;
    public BigDecimal getPayTotal(){
        return getTotal();
    }
}
